﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package Display {
    import flash.events.*;
    import Engine.Managers.*;
    import flash.display.*;
    import org.aswing.*;
    import Classes.*;
    import org.aswing.ext.*;
    import Display.aswingui.*;

    public class ItemCell extends JPanel implements GridListCell {

        protected static var HPADDING:int = 25;

        protected var m_item:Item;
        protected var m_loader:Loader;
        protected var m_itemIcon:DisplayObject;
        protected var m_gridList:GridList;
        protected var m_index:int;
        protected var m_initialized:Boolean;
        protected var m_originalPreferredWidth:Number;
        protected var m_originalPreferredHeight:Number;

        public function ItemCell(_arg1:LayoutManager=null){
            super(_arg1);
            ASwingHelper.prepare(this);
            this.m_initialized = true;
        }
        public function setGridListCellStatus(_arg1:GridList, _arg2:Boolean, _arg3:int):void{
            this.m_gridList = _arg1;
            this.m_index = _arg3;
        }
        protected function setCellSize():void{
            ASwingHelper.prepare(this);
            if (!this.m_originalPreferredWidth){
                this.m_originalPreferredWidth = this.getPreferredWidth();
            };
            if (this.m_gridList){
                if (this.m_gridList.getTileWidth() < (this.m_originalPreferredWidth + HPADDING)){
                    this.m_gridList.setTileWidth((this.m_originalPreferredWidth + HPADDING));
                } else {
                    this.setPreferredWidth(this.m_gridList.getTileWidth());
                };
                if (this.m_gridList.getTileHeight() < getPreferredHeight()){
                    this.m_gridList.setTileHeight(getPreferredHeight());
                } else {
                    this.setPreferredHeight(this.m_gridList.getTileHeight());
                };
            };
        }
        public function setCellValue(_arg1):void{
            this.m_item = _arg1;
            this.m_loader = LoadingManager.load(this.m_item.icon, this.onIconLoad, LoadingManager.PRIORITY_HIGH);
        }
        public function getCellValue(){
            return (this.m_item);
        }
        public function getCellComponent():Component{
            return (this);
        }
        protected function onIconLoad(_arg1:Event):void{
            if (this.m_loader){
                this.m_itemIcon = this.m_loader;
            };
            this.setGridListCellStatus(this.m_gridList, false, this.m_index);
            this.initializeCell();
            this.setCellSize();
        }
        protected function onIconFail(_arg1:Event):void{
        }
        protected function initializeCell():void{
        }

    }
}//package Display 
